/*
 * CollectionsAlgorithms.java
 * 
 * Created on Jun 4, 2007, 10:40:25 PM
 * 
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.infomancers.collections;

import java.util.Arrays;
import java.util.Collection;

/**
 *
 * @author aviadbd
 */
public final class CollectionsAlgorithms {

    public static <T> T findItem(Predicate<T> predicate, Iterable<T> items) {
        for (T item : items) {
            if (predicate.isTrue(item)) {
                return item;
            }
        }
        
        return null;
    }
    
    public static <T> T findItem(Predicate<T> predicate, T... items) {
        return findItem(predicate, Arrays.asList(items));
    }
    
    public static <T> void performAction(Action<T> action, Iterable<T> items) throws Exception {
        for (T item : items) {
            action.accept(item);
        }
    }
    
    public static <T> void performAction(Action<T> action, T... items) throws Exception {
        performAction(action, Arrays.asList(items));
    }
}
